package com.ftg.learn.day12.datastruct;

import java.util.*;

/**
 * 学习map
 *
 * @author 布衣
 */
public class LearnMap {

    public static void main(String[] args) {
//        Dictionary
        Map<Object, Object> map1 = new HashMap<>(8,0.5f);
        map1.put(1, "a");
        map1.put(2, "a");
        map1.put(3, "x");
        System.out.println(map1.getOrDefault(34, "abc"));
        Map<String, Object> map = new HashMap<>();
        map.put("a", "a");
        map.put("a", "acccc");
        map.put("c", "a");
        map.put("d", "a");

        //电话面试题  ibm
        Set<String> strings = map.keySet();
        for (String str : strings) {
            System.out.println(str);
            System.out.println(map.get(str));
        }

        Collection<Object> values = map.values();
        Iterator<Object> it = values.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }

        //entry - > k ,v
        Set<Map.Entry<String, Object>> entries = map.entrySet();
        for (Map.Entry e : entries) {
            System.out.println(e.getKey() + "==key");
            System.out.println(e.getValue() + "==value");
        }

        map1.putAll(map);
        map1.forEach((k, v) -> System.out.println(k + "==" + v));

        for (Map.Entry<Object, Object> objectObjectEntry : map1.entrySet()) {
            Object key = objectObjectEntry.getKey();
            if (key instanceof Integer) {
                objectObjectEntry.setValue("我的key是整数 ");
            } else {
                objectObjectEntry.setValue("我的key是字符串");
            }

        }

        map1.replaceAll((k, v) -> {
            if (k instanceof Integer) {
                return "我的key是整数 ";
            } else {
                return "我的key是字符串";
            }
        });
        System.out.println(map1);
//        List<String>
    }

}
